package game;
import java.util.ArrayList;
import java.util.List;


public class Hand implements HandItf{
	private List<Card> hand;
	private int handSum;
	private double betAmount;
	
	@Override
	public List<Card> getHand() {
		return hand;
	}

	@Override
	public int getHandSum() {
		return handSum;
	}

	@Override
	public double getBetAmount() {
		return betAmount;
	}

	@Override
	public void doubleBet() {
		betAmount *= 2;
	}

	@Override
	public void addCard(Card card) {
		hand.add(card);
		this.sumHand();
	}

    @Override
    public boolean isTwoCardsOnlyInHand() {
        return hand.size() == 2;
    }

    public Hand(Card card1,Card card2, double betAmount) {
		this.hand = new ArrayList<Card>();
		this.hand.add(card1);
		this.hand.add(card2);
		this.betAmount = betAmount;
		sumHand();
	}

	private void sumHand() {
		int sum = 0;
		int numOfAces = 0;
		
		// Sum all cards in player deck
		for (Card card : this.hand) {
			if (card.getNumber() == Card.cardNumber.ACE) {
				numOfAces = numOfAces + 1;
				sum = sum + 11;
			}	
			else
				sum = sum + card.getNumber().getNumber();
		}

		while (sum > 21 && numOfAces > 0) {
			sum = sum - 10;
			numOfAces = numOfAces - 1;
		}
			
		
		this.handSum = sum;
	}

}
